﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;

namespace Blip.UI.Controls
{
    /// <summary>
    /// Kontrolka reprezentująca animowany zegar.
    /// </summary>
    public partial class Clock : SurfaceUserControl
    {
        private Storyboard start;

        private Storyboard stop;

        /// <summary>
        /// Konstruktor inicjalizujący animowany zegar.
        /// </summary>
        public Clock()
        {
            InitializeComponent();

            start = FindResource("showClock") as Storyboard;
            stop = FindResource("hideClock") as Storyboard;
        }

        /// <summary>
        /// Wyświetla zegar z animacją.
        /// </summary>
        /// <returns>Obiekt, na rzecz którego wywoływana jest metoda</returns>
        public Clock Show()
        {
            if (Visibility == Visibility.Hidden)
            {
                Visibility = Visibility.Visible;
                start.Begin(this);
            }
            return this;
        }

        /// <summary>
        /// Ukrywa zegar.
        /// </summary>
        /// <returns>Obiekt, na rzecz którego wywoływana jest metoda</returns>
        public Clock Hide()
        {
            if (Visibility == Visibility.Visible)
                stop.Begin(this);
            return this;
        }

        private void HideCompleted(object sender, EventArgs e)
        {
            Visibility = Visibility.Hidden;
        }
    }
}
